//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Policy Injection Application Block
//===============================================================================

using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel;
using Microsoft.Practices.Unity.InterceptionExtension;

namespace EntLibContrib.PolicyInjection.CallHandlers.Configuration
{
	/// <summary>
	/// Synchronized Call Handler Data
	/// </summary>
	public class SynchronizedCallHandlerData : CallHandlerData
	{
		#region Construction
		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		public SynchronizedCallHandlerData()
		{
		}

		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		public SynchronizedCallHandlerData(string handlerName)
			: base(handlerName, typeof(SynchronizedCallHandler))
		{
		}

		/// <summary>
		/// Construct a new <see cref="SynchronizedCallHandlerData"/>.
		/// </summary>
		/// <param name="handlerName">Name of the handler.</param>
		/// <param name="handlerOrder">The handler order.</param>
		public SynchronizedCallHandlerData(string handlerName, int handlerOrder)
			: base(handlerName, typeof(SynchronizedCallHandler))
		{
			Order = handlerOrder;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Get the set of <see cref="TypeRegistration"/> objects needed to
		/// register the call handler represented by this config element and its associated objects.
		/// </summary>
		/// <param name="nameSuffix">A suffix for the names in the generated type registration objects.</param>
		/// <returns>The set of <see cref="TypeRegistration"/> objects.</returns>
		public override IEnumerable<TypeRegistration> GetRegistrations(string nameSuffix)
		{

			yield return
				new TypeRegistration<ICallHandler>(
					() => new SynchronizedCallHandler())
				{
					Name = this.Name + nameSuffix,
					Lifetime = TypeRegistrationLifetime.Transient
				};
		}
		#endregion
	}
}
